import flask
from flask import Flask, jsonify, render_template
import sqlite3
import flaskr
app = Flask(__name__)

def get_db_connection():
    conn = sqlite3.connect('database.db')
    conn.row_factory = sqlite3.Row
    return conn

# 创建数据库并插入一些示例数据
def init_db():
    conn = get_db_connection()
    conn.execute('CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, name TEXT)')
    conn.execute('INSERT INTO users (name) VALUES (?)', ('Alice',))
    conn.execute('INSERT INTO users (name) VALUES (?)', ('Bob',))
    conn.commit()
    conn.close()

# 获取所有用户信息
# @app.route('/', methods=['GET'])
# def get_users():
#     conn = get_db_connection()
#     users = conn.execute('SELECT * FROM users').fetchall()
#     conn.close()
    
#     users_list = []
#     for user in users:
#         users_list.append({'id': user['id'], 'name': user['name']})
    
#     return jsonify(users_list)

# @app.route('/')
# def hello():
#     return render_template('index.html')

if __name__ == '__main__':
    # init_db()  # 初始化数据库
    app = flaskr.create_app()
    app.run(debug=True)